<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script th:src="@{/js/ry-ui.js}"></script>
<link th:href="@{/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
<link rel="stylesheet" href="/css/xadmin.css">
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-edit" th:object="${role}">
			<input id="roleId" name="roleId" type="hidden"/>

			<div class="form-group">
				<label class="col-sm-3 control-label">菜单权限</label>
				<div class="col-sm-8">
					<div id="menuTrees" class="ztree"></div>
				</div>
			</div>
			<div class="layui-form-item" style="margin-top:40px">
				<div class="layui-input-block">
					<button class="layui-btn  layui-btn-submit" lay-submit="" onclick="submitHandler()" lay-filter="addSave">确认提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<script th:src="@{/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script type="text/javascript">
	     $(function() {
			var url = "/menupermission/roleMenuTreeData?roleId=" + $("#roleId").val();
			var options = {
				id: "menuTrees",
		        url: url,
		        check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
		        expandLevel: 0
		    };
			$.tree.init(options);
		});
	


		function edit() {
			var roleId = $("input[name='roleId']").val();
			console.log(roleId)
			var menuIds = $.tree.getCheckedNodes();
			$.ajax({
				cache : true,
				type : "POST",
				url :  "/role/editRule",
				data : {
					"roleId": roleId,
					"menuIds": menuIds
				},
				async : false,
				error : function(request) {
					layer.alert("系统错误")
				},
				success : function(data) {
                    if (data.status == 0) {
                        layer.close();
                    }
				}
			});
		}
		
		function submitHandler() {
	        	edit();
	    }
	</script>
</body>
</html>
